package com.mynetwork.gcm;

import org.json.JSONException;





import com.mynetwork.activity.MainActivity;
import com.mynetwork.data.StatisticsManager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
@class  NotiBR
@author PiaJang
@brief  상단 노티 클릭  BroadcastReceiver
*/
public class AppNotiBR extends BroadcastReceiver {
	private static final String TAG = "AppNotiBR";
	@Override
	public void onReceive(Context context, Intent intent) {
		// 노티 공지 개수 초기화!!
		GCMManager.setNotiCount(context, 0);
		String notiState = intent.getStringExtra(GCMManager.GCM_NOTI_STATE);
		if(GCMManager.GCM_NOTI_STATE_CLICKED.equals(notiState)){
			//노티가 선택된 경우!!!
			int id = intent.getIntExtra(GCMManager.GCM_NOTI_ID, -1);
			
			try {
				StatisticsManager.setConfirmPush(id);
			} catch (Exception e) {
				Log.e(TAG, "" + e);
			}
			
			//어플 활성화
			Intent returnIntent =  new Intent(Intent.ACTION_MAIN);
			returnIntent.addCategory(Intent.CATEGORY_LAUNCHER);
			returnIntent.setClassName(context,MainActivity.class.getName());
			returnIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			returnIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
			
			context.startActivity(returnIntent);
		}
		else {
			//노티가 삭제된 경우!!!
			//상단 노티 카운트 초기화!!
			GCMManager.setNotiCount(context, 0);
		}
	}
}
